﻿// Decompiled with JetBrains decompiler
// Type: XO1.TransformationOperations
// Assembly: XO1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 8FC10D3F-5BDE-46BB-8E15-DDC98B50B0AE
// Assembly location: C:\Users\KasimGulcan\Desktop\Kosgeb\DynaCAD\Project\DynaCAD\bin\Debug\XO1.dll

using System.Collections;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;

namespace XO1
{
  public static class TransformationOperations
  {
    public static void MoveUIElement(UIElement UI, double X, double Y)
    {
      if (UI.RenderTransform is TransformGroup)
      {
        if (Enumerable.Count<TranslateTransform>(Enumerable.OfType<TranslateTransform>((IEnumerable) ((TransformGroup) UI.RenderTransform).Children)) > 0)
        {
          TranslateTransform translateTransform = Enumerable.First<TranslateTransform>(Enumerable.OfType<TranslateTransform>((IEnumerable) ((TransformGroup) UI.RenderTransform).Children));
          translateTransform.X = translateTransform.X + X;
          translateTransform.Y = translateTransform.Y + Y;
        }
        else
          ((TransformGroup) UI.RenderTransform).Children.Add((Transform) new TranslateTransform()
          {
            X = X,
            Y = Y
          });
      }
      else
        UI.RenderTransform = (Transform) new TransformGroup()
        {
          Children = {
            (Transform) new TranslateTransform()
            {
              X = X,
              Y = Y
            }
          }
        };
    }

    public static void ScaleUIElement(UIElement UI, bool expand, Point Center)
    {
      if (UI.RenderTransform is TransformGroup)
      {
        if (Enumerable.Count<ScaleTransform>(Enumerable.OfType<ScaleTransform>((IEnumerable) ((TransformGroup) UI.RenderTransform).Children)) > 0)
        {
          ScaleTransform scaleTransform = Enumerable.First<ScaleTransform>(Enumerable.OfType<ScaleTransform>((IEnumerable) ((TransformGroup) UI.RenderTransform).Children));
          if (expand)
          {
            scaleTransform.ScaleX = scaleTransform.ScaleX * 1.1;
            scaleTransform.ScaleY = scaleTransform.ScaleY * 1.1;
            TransformationOperations.MoveUIElement(UI, (Mouse.GetPosition((IInputElement) UI).X - Center.X) * scaleTransform.ScaleX, (Mouse.GetPosition((IInputElement) UI).Y - Center.Y) * scaleTransform.ScaleY);
          }
          if (expand)
            return;
          scaleTransform.ScaleX = scaleTransform.ScaleX * 0.9;
          scaleTransform.ScaleY = scaleTransform.ScaleY * 0.9;
          TransformationOperations.MoveUIElement(UI, (Mouse.GetPosition((IInputElement) UI).X - Center.X) * scaleTransform.ScaleX, (Mouse.GetPosition((IInputElement) UI).Y - Center.Y) * scaleTransform.ScaleY);
        }
        else
        {
          ScaleTransform scaleTransform = new ScaleTransform();
          if (expand)
          {
            scaleTransform.ScaleX = 1.1;
            scaleTransform.ScaleY = 1.1;
            TransformationOperations.MoveUIElement(UI, (Mouse.GetPosition((IInputElement) UI).X - Center.X) * scaleTransform.ScaleX, (Mouse.GetPosition((IInputElement) UI).Y - Center.Y) * scaleTransform.ScaleY);
          }
          if (!expand)
          {
            scaleTransform.ScaleX = 1.0;
            scaleTransform.ScaleY = 1.0;
            TransformationOperations.MoveUIElement(UI, (Mouse.GetPosition((IInputElement) UI).X - Center.X) * scaleTransform.ScaleX, (Mouse.GetPosition((IInputElement) UI).Y - Center.Y) * scaleTransform.ScaleY);
          }
          ((TransformGroup) UI.RenderTransform).Children.Insert(0, (Transform) scaleTransform);
        }
      }
      else
      {
        TransformGroup transformGroup = new TransformGroup();
        ScaleTransform scaleTransform = new ScaleTransform();
        if (expand)
        {
          scaleTransform.ScaleX = 1.1;
          scaleTransform.ScaleY = 1.1;
        }
        if (!expand)
        {
          scaleTransform.ScaleX = 1.0;
          scaleTransform.ScaleY = 1.0;
        }
        transformGroup.Children.Insert(0, (Transform) scaleTransform);
        UI.RenderTransform = (Transform) transformGroup;
      }
    }
  }
}
